<include file="__THEME__/header" />
<script>
 function doInvite() {

  		var uids = document.getElementsByName('uids[]');
		var gid = {$gid};
		id = [];
        for(i=0;i<uids.length;i++){
          	uids[i].checked && id.push(uids[i].value);
        }

       if(!checkFriendForm()) { return false;}

       $.ajax( {
      		type: 'POST',
      		url: APP+'/Invite/sendFriendInvite/',
      		data:"gid="+gid+"&uids="+id,
      		success:function( result ){

      			if(result == 1){
      				alert('邀请成功');
      				$('#first').hide();
    				$('#end').show();
      			}else{
      				alert('邀请失败');
      			}
      		}
   		 })

   }
</script>
<link href="../Public/friend.css" rel="stylesheet" type="text/css" />

<div class="content"><!-- 内容 begin  -->
    <div id="flashcopier"></div>
    <include file="__THEME__/apps" /><!-- 用户组件列表 end -->
    <div class="main"><!-- 右侧内容 begin  -->
    <div class=page_title>
            <!-- page_title begin -->
             <h2><span class="right fn f12px"> <a href="javascript:window.history.back();">&lt;&lt;返回上一页</a></span><img src="../Public/images/web_mail.gif" />邀请朋友加入{$site_name}网</h2>
        </div>
    <form method="post">
    <div style="margin:40px 0 50 30px;" id="first"  <php> if(!count($emailArr['sendInviteFriend'])) { </php> $('#first').hide(); <php> } </php> >
    <div class="f14px lh25"> <strong>你的通讯录里的联系人，已有<php>echo count($emailArr['sendInviteFriend'])</php>人在{$site_name}了。你可以加他们为好友</strong></a></div>
    <div class="border mb5" style="overflow: auto;	width: 600px;height: 260px;">
    	<div class="bg02 btmline lh25 mb10 pl5" style="height:25px; margin-top:1px;"><input name="friendflag" type="checkbox" value="" id="friendflag" onclick="selectAll('friendflag','uids')" />全选</div>
        <volist name="emailArr['sendInviteFriend']" id="user">
    	<div class="btmlineD pb5 pt5">
        	<div class="left pl5" style="width:30px;"><input name="uids[]" type="checkbox" value="{$user.uid}" id="uids[]" /></div>
            <div class="left" style="width:70px;"><span class="headpic50"><a href="__TS__/space/{$user.uid}"><img src="{$user.uid|getUserFace}" /></a></span></div>
            <div class="left lh20" style="width:450px;"><a href="__TS__/space/{$user.uid}">{$user.username}</a><br />{$user.sex|getUserSex}&nbsp;&nbsp;{$user.current_province|getUserCity}</div>
            <div class="c"></div>
        </div>
        </volist>

    </div>
    <div>
    	<input type="hidden" name="gid" value="{$gid}">
    	<input type="button" value="加为好友" onclick="doInvite();"class="btn_b mr5"/><input type="button" value="跳过" onclick="jump();"class="btn_w" /></div>
    </div>
    </form>

    <form method="post" action="__URL__/doSendRegInvite" onsubmit="return checkRegForm();">
    <div style="margin:40px 0 0 30px;display:none;" id="end">
    <div class="f14px lh25"> <strong>以下是该通讯录里的其他联系人，请选择邀请对象</strong></a></div>
    <div class="border mb5" style="overflow: auto;	width: 600px;height: 260px;">
    	<div class="bg02 btmline lh25 mb5 pl5" style="height:25px; margin-top:1px;"><input name="regflag" id="regflag" type="checkbox" value="" onclick="selectAll('regflag','emails')" />全选</div>

    	 <volist name="emailArr['sendInviteReg']" id="userEmail">
    	<div class="btmlineD">
        	<div class="left pl5" style="width:30px;"><input name="emails[]" type="checkbox" value="{$userEmail}" /></div>
            <div class="left lh20" style="width:170px;display:none;">张健</div>
            <div class="left lh20" style="width:350px;">&lt;{$userEmail}&gt;</div>
            <div class="c"></div>
        </div>
       </volist>

    </div>
    <div class="FList">
    	<ul>
          <li class="li">
            <div class="left alR cGray2 f12px lh25" style="width: 10%;"> 好友类型：</div>
            <div class="left cGray2" style="width: 80%;">
              <select name="code" class="TextH20" id="groupsel">
                <volist name="groups" id="vo">
                  <php>
                                                $code_arr = array($mid,$my_name,$vo["id"],$gid);
                                                $code = json_encode($code_arr);
                                                $code = jiami($code);
                                            </php>
                  <option value="{$code}">{$vo.name}</option>
                </volist>
              </select>
            </div>
          </li>
          <li class="li">
            <div class="left alR cGray2 f12px lh25" style="width: 10%;"> 邀请留言：</div>
            <div class="left cGray2" style="width: 80%;">
              <textarea  style="width: 490px; height: 150px;" name="content" id="content">{$site_opts.invite_content}</textarea>
            </div>
          </li>
          <li class="li">
            <div class="left alR cGray2 f12px lh25" style="width: 10%;"> 你的姓名：</div>
            <div class="left cGray2" style="width: 80%;">
              <input type="text" name="name" class="Text2" value="{:getUserName($mid);}" >
            </div>
          </li>
          <li class="li">
            <div class="left alR" style="width: 10%;">&nbsp;</div>
            <div class="left cGray2" style="width: 80%;">
              <input type="hidden" name="gid" value="{$gid}">
              <input  type="submit" class="btn_b" id="button" value="发送邀请" /> <input  type="button" class="btn_w" value="取消" onclick="window.location.href='index.php'"/>
            </div>
          </li>
        </ul>
        <div class="c"></div>
</div>
</div>
</form>
  </div>
   <div class="c"></div>
  </div><!-- 右侧内容 end  -->

<script>
    function selectAll(name,selectdName){


    	if($("input[name='"+name+"']").attr('checked')){

    		$("input[name='"+selectdName+"[]']").each(function(){
                $(this).attr('checked',true);
            });

    	}else{
    		$("input[name='"+selectdName+"[]']").each(function(){
                $(this).attr('checked',false);
            });

    	}
    }

    function jump(){
    	$('#first').hide();
    	$('#end').show();
    }

    function checkFriendForm(){
    	var flag = false;
    	$("input[name='uids[]']").each(function(){

                if($(this).attr('checked')) { flag = true;}
            });
       	if(flag){
       		return true;
       	}else{
       		alert('请选择邀请人');
       		return false;
       	}
    }

    function checkRegForm(){
    	var flag = false;
    	if(!$.trim($('#content').val())) { alert('请输入邀请留言内容'); return false;}
    	$("input[name='emails[]']").each(function(){

                if($(this).attr('checked')) { flag = true;}
            });
       	if(flag){
       		return true;
       	}else{
       		alert('请选择邀请人');
       		return false;
       	}
    }
 <php>if(!count($emailArr['sendInviteFriend'])) { </php> jump()  <php> } </php>
</script>

<include file="__THEME__/footer" />